package main
import (
	"fmt"
	"errors"
)

func f(arg int) (int,error){
	if arg == 42{
		return -1,errors.New("cannot work with 42")
	}
	return arg + 3,nil
}

var OutOfTea = fmt.Errorf("no more tea available")
var ErrorPower = fmt.Errorf("cannot boil water")

func makeTea(arg int) error{
	if arg == 2{
		return OutOfTea
	}else if arg == 4{
		return fmt.Errorf("make tea %w",ErrorPower)
	}else {
		return nil
	}

}


func main(){
	for _,v:=range []int{7,42}{
		if r,e:=f(v);e!=nil{
			fmt.Println("error :",e)
		}else{
			fmt.Println("success :",r)
		}
	}

	for i:=range 5{
		if e:=makeTea(i);e!=nil{
			if errors.Is(e,OutOfTea){
				fmt.Println("need to purchase more tea")
			}else if errors.Is(e,ErrorPower){
				fmt.Println("now it is dark")
			}else{
				fmt.Print("unknow error %s",e)
			}
			continue
		}
		fmt.Println("Tea is ready!")
	}
}
